//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "ReadCathInfo.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  String* namefileCDDF         = NULL;
  String* namefileCLF          = NULL;

  String* namefileFASTA        = NULL;
  String* namefileFASTAProfile = NULL;
  String* namefileDescription  = NULL;

  if (argc < 4) {
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./ConstructFASTACATHComplete <Input CDDF File> <Input CLF File> <Output name for Files>" << endl;
    return 0;
  }
  else {
    
    namefileCDDF         = new String(argv[1]);
    namefileCLF          = new String(argv[2]);
    
    namefileFASTA        = new String(argv[3]);
    namefileFASTAProfile = new String(argv[3]);
    namefileDescription  = new String(argv[3]);
    
    namefileFASTA->Add(".fasta");
    namefileFASTAProfile->Add(".profile.dat");
    namefileDescription->Add(".description.dat");
    
    cout << "---------------------------------------------------------------------------------" << endl;
    cout << "           Input CDDF File : " << argv[1] << endl;
    cout << "            Input CLF File : " << argv[2] << endl;
    cout << "         Output FASTA File : " << namefileFASTA->Out() << endl;
    cout << " Output FASTA Profile File : " << namefileFASTAProfile->Out() << endl;
    cout << "   Output Description File : " << namefileDescription->Out() << endl;
    cout << "---------------------------------------------------------------------------------" << endl;
    
  }
  
  ReadCathInfo* readCathInfo = new ReadCathInfo ();
  
  cout << "Preparing Files..." << endl;
  readCathInfo->NamefileCDDF(namefileCDDF);
  readCathInfo->NamefileCLF(namefileCLF);
  
  readCathInfo->NamefileFASTA(namefileFASTA);
  readCathInfo->NamefileFASTAProfile(namefileFASTAProfile);
  readCathInfo->NamefileDescription(namefileDescription);
  
  cout << "Reading CATH File with Domain Descriptions..." << endl;
  readCathInfo->ReadDomainDescription();
  
  cout << "Number of Domains: " << readCathInfo->DomainDescriptions()->ListDomainInfo()->Length() << endl;
    
  cout << "Ordering Domains Descriptions List..." << endl;
  readCathInfo->OrderListDomain();
  cout << "Reading CATH File with Codes..." << endl;
  readCathInfo->ReadDomainListCode();
  
  cout << "Matching the Information of Files..." << endl;
  readCathInfo->MatchDomainInfo();
  
  cout << "Preparing the output Files..." << endl;
  readCathInfo->OutFASTAFile();
  readCathInfo->OutFASTAProfile();
  readCathInfo->OutDescriptionDomain();
  
  if (readCathInfo)         delete readCathInfo;
  
  if (namefileCDDF)         delete namefileCDDF;
  if (namefileCLF)          delete namefileCLF;

  if (namefileFASTA)        delete namefileFASTA;
  if (namefileFASTAProfile) delete namefileFASTAProfile;
  if (namefileDescription)  delete namefileDescription;
  
  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

